function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function trim(value)
{
return value.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 

function str_replace(search, replace, subject) {
    // *     example 1: str_replace(' ', '.', 'toto titi');
    // *     returns 1: 'toto.titi'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
 
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

function function_exists(function_name) {
    if (typeof function_name == 'string'){
        return (typeof window[function_name] == 'function');
    } else{
        return (function_name instanceof Function);
    }
}

function _p(variable) {
	if(console != 'undefined')
		console.log(variable);
}

function _d(variable) {
	_p(variable)
	alert('Script is now paused until you click the \'ok\' button...');
}

function _getClassAttribute(prefix, $element)
{
	var pattern = new RegExp(prefix+'([^\ ]*)');
	var result = pattern.exec($element.get(0).className);
	if (result == null || !is_array(result) || result.length != 2)
		return false;
	return result[1];
}

function is_array( mixed_var ) {
    if (!mixed_var) {
        return false;
    }
    if (typeof mixed_var === 'object') {
        // Uncomment to enable strict JavsScript-proof type checking
        // This will not support PHP associative arrays (JavaScript objects)
        //  if (mixed_var.propertyIsEnumerable('length') || typeof mixed_var.length !== 'number') {
        //      return false;
        //  }
        return true;
    }
    return false;
}

function in_array(array, value) {
	for (var i in array) if (array[i] == value) return i;
	return false;
}

function rewrite_tr_alternate_class($table) {
	$('table.listing').find('tbody > tr').removeClass('alternate').each(function(i){
		if (i % 2 == 0)
			$(this).addClass('alternate');
	});
}

function tb_alert(string, theTitle){
	if (function_exists('tb_show'))
	{
		var title = '';
		if (theTitle != undefined)
			title = theTitle;
		$('body').append('<div id="hiddenModalContent" style="display:none">\
			<p>'+string+'</p>\
			<p style="text-align:center"><input type="button" value="&nbsp;&nbsp;Ok&nbsp;&nbsp;" onclick="tb_remove()" /></p>\
		</div>');
		//TODO : set the good height for long text
		var height = $('#hiddenModalContent').height() + 25;
		tb_show(theTitle, 'http://localhost/projets/kasifimusicmanager/?step=downloaded#TB_inline?&height='+height+'&width=500&inlineId=hiddenModalContent'+(title == '' ? '&modal=true' : ''), false);
	}
	else alert(string);
}
